package com.baizhi.zjs.action;

import java.util.List;

import com.baizhi.zjs.entity.CategoryEntity;
import com.baizhi.zjs.service.CategoryService;
import com.baizhi.zjs.service.CategoryServiceImpl;
import com.baizhi.zjs.util.UUIDUtil;
import com.opensymphony.xwork2.ActionSupport;

public class CategorAction extends ActionSupport {
	//创建service对象方便调用
	
	//创建List成员变量
	private List<CategoryEntity> list3;
private 	 List<CategoryEntity> list;
private CategoryEntity cater;
private Integer levels;
private String name;
private String Ti;

	//查询所有类别情况
public String categryShoeAll(){
	System.out.println("categoryAction------------");
	CategoryService impl = new CategoryServiceImpl();
	 list = impl.cateShowAll();
	return "showAll";
}
//添加类别
public String addCateg(){
	System.out.println("跳转到添加页面======");
	System.out.println(name);
	System.out.println(levels);
	//创建uuid
	String uuid = UUIDUtil.getUuid();
	CategoryService impl = new CategoryServiceImpl();
	
	
	//创建实体类对象，并将值存入//id,类别名，数量，所属类别，类别等级
	CategoryEntity entity = new CategoryEntity(uuid,name,0,null,levels);
	
System.out.println(entity);
	impl.addCate(entity);
	return "addCat";
}

//查询所有的一级类别
public String querylevelsOne(){
	System.out.println("查询所有的一级类别Action============");
	//调用查询一级类别的方法
	CategoryService impl = new CategoryServiceImpl();
	list = impl.showOnecateg();
	System.out.println(list);
	return "levelsOne";
}

//添加二级类别
public String addTwoLevels(){
	System.out.println(cater);
	String uuid = UUIDUtil.getUuid();
	cater.setId(uuid);
	cater.setCount(0);
	CategoryService impl = new CategoryServiceImpl();
	impl.addCate(cater);
	return "addCat";
}

//删除类别Action
public String deleteCategory(){
	//获取要删除类别的id和levels级别
	System.out.println("删除action========");
	System.out.println(cater);
	String id1=cater.getId();
	int levels1=cater.getLevels();
	CategoryService impl = new CategoryServiceImpl();
	//判断给类别是一级类别还是二级类别
	if(cater.getLevels()==1){
		//如果是一级类别判断类别下有没有二级类别，如果有二级类别不能被删除
		List<CategoryEntity> list2 = impl.showParentId(cater.getId());
		if(list2.size()!=0){
			Ti="erorr";
			return "addCat";
		}
	}
	impl.deleteCategory(id1);
	Ti="ok";
	return "addCat";
}


	






//-----------------------------------------------------
public List<CategoryEntity> getList() {
	return list;
}
public void setList(List<CategoryEntity> list) {
	this.list = list;
}

public String getName() {
	return name;
}
public void setName(String name) {
	this.name = name;
}
public Integer getLevels() {
	return levels;
}
public void setLevels(Integer levels) {
	this.levels = levels;
}
public CategoryEntity getCater() {
	return cater;
}
public void setCater(CategoryEntity cater) {
	this.cater = cater;
}
public List<CategoryEntity> getList3() {
	return list3;
}
public void setList3(List<CategoryEntity> list3) {
	this.list3 = list3;
}
public String getTi() {
	return Ti;
}
public void setTi(String ti) {
	Ti = ti;
}


 
}
